package com.seata1.controller;

import com.mybatisflex.annotation.UseDataSource;
import com.seata1.entity.TUser;
import com.seata1.service.TUserService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.gavin.core.domain.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * UserController
 *
 * @author grl
 * @date 2024/4/22
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class UserController {

    private final TUserService userService;

    //@GlobalTransactional(name = "saveUser")
    @UseDataSource(value = "db2")
    @PostMapping(value = "/seata/save")
    public R<Boolean> save(){
        TUser user = new TUser();
        user.setAge(201);
        user.setUsername("张三1");
        user.setCreateTime(LocalDateTime.now());
        user.setPassword("1234561");
        boolean save = userService.save(user);
        return R.ok(save);
    }
}
